package managementSys.student;

import java.util.ArrayList;
import java.util.Scanner;

import managementSys.student.StudentModel;
import managementSys.student.StudentFunction;

public class StudentFunction {
	public static void main(String[] args) {
		StudentFunction bb = new StudentFunction();
		bb.start();
	}
	ArrayList<StudentModel> list = new ArrayList<StudentModel>();//在外部定义，存储信息
	Scanner sc = new Scanner(System.in);
	public void start() {
		while(true) {
			System.out.println("=====欢迎使用学生档案管理======");
			System.out.println("=====键入数字使用功能======");
			System.out.println("----------1.录入学生信息");
			System.out.println("----------2.查看全部学生信息");
			System.out.println("----------3.按姓名查询学生");
			System.out.println("----------4.按专业查询学生");
			System.out.println("----------0.退出");
			switch (Integer.parseInt(sc.nextLine())) {
			case 1:
				inputs();				//录入信息
				System.out.println("hhhhhhh");
				break;
			case 2:						
				seeAll();				//查看所有学生的信息
				break;
			case 3:
				getOneByName();			//按姓名查询
				break;
			case 4:
				getOneByCategory();		//按专业查询
				break;
			}
			System.out.println("*************是否退出系统?Y/N");
			if("Y".equalsIgnoreCase(sc.nextLine()))
				break;
		}
	}
	public void inputs() {			//控制多次输入
		while(true) {
			input();
			System.out.println("是否继续输入？Y/N");
			if("N".equalsIgnoreCase(sc.nextLine()))
				return;
		}
		
	}
	
	public void input() {			//控制单次输入
		StudentModel model = new StudentModel();	//model像一个工具盒，把每个小空间填满后，放到list中
		System.out.println("请输入学生姓名:");
		String name = sc.nextLine();
		do {										//判重
			System.out.println("请输入题号");
			name = sc.nextLine();
		}while(isExist(name));
		System.out.println("请输入专业");
		model.setCategory(sc.nextLine());
		list.add(model);
	}
	public boolean isExist(String name) {			//判断某个题号在集合中是否存在
		for(StudentModel model:list) {
			if(model.getName().equals(name)) {
				System.out.println("姓名");
				return true;
			}
		}
		return false;
	}
	public void seeAll() {
		for(StudentModel model:list) {
			System.out.println("名字是："+model.getName()+"\n"+"专业是："+model.getCategory());
		}
	}
	public void getOneByName() {
		System.out.println("请输入要查找的姓名");
		String name = sc.nextLine();
		for(int i = list.size()-1;i>=0;i--) {
			StudentModel model = list.get(i);
			if(model.getName().equals(name)) {
				System.out.println("已经找到了:");
				System.out.println("名字是："+model.getName()+"\n"+"专业是："+model.getCategory());
				return;
			}
		}
//		for(int i = list.size();i>=0;i--) {
//			StudentModel model = list.get(i);
//			if(model.getName() == name) {
//				list.remove(i);
//				System.out.println("已经删除了");
//				return;
//			}
//		}
	}
	public void getOneByCategory() {
		System.out.println("请输入要查找的专业");
		String category = sc.nextLine();
		for(int i = list.size()-1;i>=0;i--) {
			StudentModel model = list.get(i);
			if(model.getCategory().equals(category)) {
				System.out.printf("本专业有：%s\n");
			}
		}
	}
}

